#!/usr/bin/python3
# coding=utf-8
# 查询公司信息目录
from pytdx.hq import TdxHq_API
from pytdx.params import TDXParams
import io
import sys
api = TdxHq_API()
argc=len(sys.argv)
code='002415'
if(argc>1):
    code=sys.argv[1]

if api.connect('119.147.212.81', 7709):
    data = api.get_company_info_category(TDXParams.MARKET_SZ, code)#返回一心堂公司信息目录
    data = api.to_df(data) # 返回DataFrame
    #print(data)
    # f = "../data/txt/"+code+".txt"
    # data.to_csv(f, sep='\t',index=True, header = True)

    # column_indexs = []
    # for column_index, row_data in data.iteritems():
    #     column_indexs.append(column_index)
    #     print(row_data)
    #     #print(column_indexs)
    
    # row_indexs = []
    # for index, row in data.iterrows():
    #     row_indexs.append(index)
    #     print(row)

    # for row in data.itertuples():
    #     print(getattr(row, 'name'), getattr(row, 'filename'), getattr(row, 'start'), getattr(row, 'length'))
    #     print(type(row))
    for index,row in data.iterrows():
        #print(data.loc[index])
        print("-----------")
        print(index,end=" ")
        print(row['name'],end=" ")
        print(row['filename'],end=" ")
        print(row['start'],end=" ")
        print(row['length'])

    api.disconnect()